<?php
namespace App\Http\Controllers\Home;
use App\http\Controllers\Controller;
use Illuminate\Support\Facades\DB;


class BlogController extends BaseController{

    //博客列表
    public function blog(){

        return view('home/blog');
    }

    //博客列表
    public function blog_list(){
        $this->go_login();
        $blog_list = DB::table('blog') -> orderBy('blog_time','DESC') -> paginate(9);
        foreach ($blog_list -> items() as $k => $v) {
            //标题
            $blog_title = $v -> blog_time;
            $blog_title = msubstr($blog_title,0,15,'utf-8', true);
            $blog_list -> items()[$k] -> blog_time = $blog_title;

            //内容
            $blog_desc = $v -> blog_desc;
            $blog_desc = msubstr($blog_desc,0,200,'utf-8', true);
            $blog_list -> items()[$k] -> blog_desc = $blog_desc;

            //图片
            $blog_photo = $v -> blog_photo;
            $blog_photo = $blog_photo==''?'/static/home/img/blog/3.jpg':'/uploads/'.$blog_photo;
            $blog_list -> items()[$k] -> blog_photo = $blog_photo;
        }
        foreach ($blog_list as $v){
            echo '
                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                    <div class="single-blog mb-30">
                        <div class="blog-photo">
                            <a href="#"><img src="'.$v -> blog_photo.'" alt="" /></a>
                            <div class="like-share text-center fix">
                                <a href="#"><i class="zmdi zmdi-favorite"></i><span>'.$v -> blog_like.'</span></a>
                                <a href="#"><i class="zmdi zmdi-comments"></i><span>'.$v -> blog_comments.'</span></a>
                                <a href="#"><i class="zmdi zmdi-share"></i><span>'.$v -> blog_share.'</span></a>
                            </div>
                        </div>
                        <div class="blog-info">
                            <div class="post-meta fix">
                                <div class="post-date floatleft"><span class="text-dark-red">'.date("d",$v -> blog_time).'</span></div>
                                <div class="post-year floatleft">
                                    <p class="text-uppercase text-dark-red mb-0">'.date("Y-m",$v -> blog_time).'</p>
                                    <h4 class="post-title"><a href="#" tabindex="0">'.$v -> blog_time.'</a></h4>
                                </div>
                            </div>
                            <p>'.$v -> blog_desc.'</p>
                            <a href="#" class="button-2 text-dark-red">Read more...</a>
                        </div>
                    </div>
                  </div>
            ';
        }
        echo '
             <div class="row">
                <div class="col-md-12">
                    <!-- Pagination start -->
                    <div class="shop-pagination  text-center">
                        <div class="pagination">
                            '.$blog_list -> links('pagination::default').'
                        </div>
                    </div>
                    <!-- Pagination end -->
                </div>
        ';
    }

    //博客详情页
    public function single_blog(){
        $this->go_login();
        return view('home/single_blog');
    }



}